home *** CD-ROM | disk | FTP | other *** search
- UNIT fix_mod;
-
- {$O+}
-
- { ------------------------------------------------------------------
-
- This program and its associates implement in Turbo Pascal v5
- the aritmetic encoding/decoding algorithms presented in the papers
-
- "Arithmetic Coding for Data Compression"
-
- by Ian H. Witten
- Radford M. Neal
- John G. Cleary
-
- pp 520 - 540 of June 1987 Communications of the ACM
-
- and
-
- "An Adaptive Dependency Source Model For Data Compression"
-
- by David M. Abrahamson
-
- pp 77 - 83 of January 1989 Communications of the ACM
-
- ------------------------------------------------------------------
-
- Implemented by Ken Westerback : CompuServe 73547,3520
-
- version 1.0 released 89/02/19
- version 2.0 released 89/02/27
-
- These programs, units and associated documentation are released
- into the public domain to be used and abused as your whims
- dictate.
-
- Feel free to distribute/incorporate/improve as desired.
-
- >>>>> Use at your own risk! <<<<<
-
- Comments and suggestions welcome via CompuServe.
-
- ------------------------------------------------------------------
- }
-
-
- INTERFACE
-
-
- const model_name = 'Fixed Model';
-
- { this procedure initializes the model - must be exported cuz we }
- { may be overlay'ed }
-
- procedure start_model;
-
- function select_char ( symbol : integer ) : char;
-
- function select_symbol ( ch : char ) : integer;
-
- procedure update_model ( symbol : integer );
-
-
- IMPLEMENTATION uses model_h;
-
-
- { make these arrays dynamic so multiple model overlays will not }
- { use up unnecessary memory, or worse, use the same memory for }
- { different things! }
-
- type ctoi_array = array [ 0..no_of_chars-1 ] of integer;
- itoc_array = array [ 0..no_of_symbols ] of char;
-
- ctoi_p = ^ctoi_array;
- itoc_p = ^itoc_array;
-
-
- var char_to_index : ctoi_p; { to index from character }
- index_to_char : itoc_p; { to character from index }
-
-
- procedure start_model;
-
- var i : integer;
-
- begin
-
- new ( index_to_char );
- new ( char_to_index );
-
- { set up frequency table to constant values }
-
- freq[ 0 ] := 0;
- for i := 1 to no_of_symbols do
- freq[ i ] := 1;
-
- { a typed constant would work here, but this method makes }
- { this model compatible with all others }
- { all characters not explicitly mentioned here are left }
- { with a frequency of 1 from the previous loop }
-
- freq[ ord( 'A' )+1 ] := 24; freq[ ord( 'a' )+1 ] := 491;
- freq[ ord( 'B' )+1 ] := 15; freq[ ord( 'b' )+1 ] := 85;
- freq[ ord( 'C' )+1 ] := 22; freq[ ord( 'c' )+1 ] := 173;
- freq[ ord( 'D' )+1 ] := 12; freq[ ord( 'd' )+1 ] := 232;
- freq[ ord( 'E' )+1 ] := 15; freq[ ord( 'e' )+1 ] := 744;
- freq[ ord( 'F' )+1 ] := 10; freq[ ord( 'f' )+1 ] := 127;
- freq[ ord( 'G' )+1 ] := 9; freq[ ord( 'g' )+1 ] := 110;
- freq[ ord( 'H' )+1 ] := 16; freq[ ord( 'h' )+1 ] := 293;
- freq[ ord( 'I' )+1 ] := 16; freq[ ord( 'i' )+1 ] := 418;
- freq[ ord( 'J' )+1 ] := 8; freq[ ord( 'j' )+1 ] := 6;
- freq[ ord( 'K' )+1 ] := 6; freq[ ord( 'k' )+1 ] := 39;
- freq[ ord( 'L' )+1 ] := 12; freq[ ord( 'l' )+1 ] := 250;
- freq[ ord( 'M' )+1 ] := 23; freq[ ord( 'm' )+1 ] := 139;
- freq[ ord( 'N' )+1 ] := 13; freq[ ord( 'n' )+1 ] := 429;
- freq[ ord( 'O' )+1 ] := 11; freq[ ord( 'o' )+1 ] := 446;
- freq[ ord( 'P' )+1 ] := 14; freq[ ord( 'p' )+1 ] := 111;
- freq[ ord( 'Q' )+1 ] := 1; freq[ ord( 'q' )+1 ] := 5;
- freq[ ord( 'R' )+1 ] := 14; freq[ ord( 'r' )+1 ] := 388;
- freq[ ord( 'S' )+1 ] := 28; freq[ ord( 's' )+1 ] := 375;
- freq[ ord( 'T' )+1 ] := 29; freq[ ord( 't' )+1 ] := 531;
- freq[ ord( 'U' )+1 ] := 6; freq[ ord( 'u' )+1 ] := 152;
- freq[ ord( 'V' )+1 ] := 3; freq[ ord( 'v' )+1 ] := 57;
- freq[ ord( 'W' )+1 ] := 11; freq[ ord( 'w' )+1 ] := 97;
- freq[ ord( 'X' )+1 ] := 1; freq[ ord( 'x' )+1 ] := 12;
- freq[ ord( 'Y' )+1 ] := 3; freq[ ord( 'y' )+1 ] := 101;
- freq[ ord( 'Z' )+1 ] := 1; freq[ ord( 'z' )+1 ] := 5;
-
- freq[ ord( '0' )+1 ] := 15; freq[ ord( '1' )+1 ] := 15;
- freq[ ord( '2' )+1 ] := 8; freq[ ord( '3' )+1 ] := 5;
- freq[ ord( '4' )+1 ] := 4; freq[ ord( '5' )+1 ] := 7;
- freq[ ord( '6' )+1 ] := 5; freq[ ord( '7' )+1 ] := 4;
- freq[ ord( '8' )+1 ] := 4; freq[ ord( '9' )+1 ] := 6;
-
- freq[ ord( ' ' )+1 ] := 1236; freq[ ord( ';' )+1 ] := 2;
- freq[ ord( '"' )+1 ] := 21; freq[ ord( '.' )+1 ] := 60;
- freq[ ord( '#' )+1 ] := 9; freq[ ord( '-' )+1 ] := 19;
- freq[ ord( '$' )+1 ] := 3; freq[ ord( '*' )+1 ] := 2;
- freq[ ord( '&' )+1 ] := 25; freq[ ord( ',' )+1 ] := 79;
- freq[ ord( '{' )+1 ] := 2; freq[ ord( '}' )+1 ] := 2;
- freq[ ord( '(' )+1 ] := 2; freq[ ord( ')' )+1 ] := 2;
- freq[ ord( '"' )+1 ] := 21; freq[ ord( '*' )+1 ] := 2;
- freq[ ord( ':' )+1 ] := 3; freq[ ord( '~' )+1 ] := 3;
-
- freq[ ord( '''' )+1 ] := 15;
-
- freq[ 11 ] := 124;
-
- { set up tables that translate between symbol indexes and characters }
-
- for i := 0 to no_of_chars - 1 do
- begin
- char_to_index^[ i ] := i+1;
- index_to_char^[ i+1 ] := chr ( i );
- end;
-
- { set up cumulative frequency counts }
-
- cum_freq[ no_of_symbols ] := 0;
-
- for i := no_of_symbols downto 1 do
- cum_freq[ i-1 ] := cum_freq[ i ] + freq[ i ];
-
- { check that counts are within the limit }
-
- if ( cum_freq[ 0 ] > max_frequency ) then
- begin
- writeln ;
- writeln ( 'fixed : cumulative frequence exceeds max_frequency' );
- writeln ;
- halt;
- end;
-
- end;
-
- function select_symbol;
-
- begin
-
- select_symbol := char_to_index^[ ord( ch ) ];
-
- end; { select symbol }
-
-
- function select_char;
-
- begin
-
- select_char := index_to_char^[ symbol ];
-
- end; { select_char }
-
-
- procedure update_model;
- begin
-
- { this being a fixed model, we need do nothing! }
-
- end { update model };
-
-
- END. { fixed model implementation }